//
//  LottTableViewController.m
//  SXNews
//
//  Created by ivan on 2017/8/29.
//  Copyright © 2017年 ShangxianDante. All rights reserved.
//

#import "LottTableViewController.h"
#import "LTHead1ViewCell.h"
#import "LTHead2ViewCell.h"
#import "WebViewController.h"

@interface LottTableViewController (){
    NSArray *dataArr;
}
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@end

@implementation LottTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"彩迷";

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    self.tableView.estimatedRowHeight = 100;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    
    NSDictionary*dic1 = @{@"image":@"631979.jpg",@"title":@"无锡福彩\"大走访\"失母女孩为大学学费发愁",
                          @"time":@"8-20",@"url":@"wwww"};
    NSDictionary*dic2 = @{@"image":@"631243.jpg",@"title":@"承德彩民10元刮出“扑克风云”25万大奖",
                          @"time":@"8-18",@"url":@"zzz"};
    
    NSDictionary*dic3 = @{@"image":@"631983_500x500.jpg",@"title":@"亳州各地纷纷开展走进公益金项目活动",
                          @"time":@"8-23",@"url":@"333"};
    
    
    dataArr = [NSArray arrayWithObjects:dic1,dic2,dic3, nil];
//  @[dic1,dic2,dic3];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
    return section == 0?1:dataArr.count;
}

- (UIView *)tableView:(UITableView *)atableView viewForHeaderInSection:(NSInteger)section {
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, atableView.frame.size.width, 50)];
    view.backgroundColor = [UIColor clearColor];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.tableView.width, 40)];
    label.font = [UIFont systemFontOfSize:13];
    label.textColor = [UIColor blackColor];
    label.numberOfLines = 0;
    label.text = section == 0?@"今日分享":@"彩迷那些事";
    
    return view;
    
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if(indexPath.section == 0){
        
        LTHead1ViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:@"LTHead1ViewCell_ID"];
        return cell;

    }else{
        LTHead2ViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:@"LTHead2ViewCell_ID"];
        
        NSDictionary *dic = dataArr[indexPath.row];
        cell.imgView.image = [UIImage imageNamed:dic[@"image"]];
        cell.titleL.text = dic[@"title"];
        cell.timeLabel.text = dic[@"time"];

        return cell;
        
    }

    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     if (indexPath.section == 1){
       
         WebViewController *w = [WebViewController new];
         w.hidesBottomBarWhenPushed = YES;
         
         NSDictionary *dic = dataArr[indexPath.row];
         NSString*str=[NSString stringWithFormat:@"html/%@",dic[@"url"]];
         
         NSString *path = [[NSBundle mainBundle] pathForResource:str ofType:@"html"];
         w.urlStr = path;
         [self.navigationController pushViewController:w animated:YES];

     }
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
